package com.arvato.wxwork.service.store;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.arvato.minipro.bean.bean_dto.common.PageData;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.wxwork.bean.bean_do.store.WxworkStoreDo;
import com.arvato.wxwork.bean.bean_vo.store.WxworkStoreVo;
import com.arvato.wxwork.mapper.store.WxworkStoreMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service
@Transactional
public class WxworkStoreService {
	
	@Autowired
	private WxworkStoreMapper wxworkStoreMapper;
	
	/**
	 * 批量查询门店信息(分页)
	 * @param query
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageData listStoreByQuery(Query query, Integer pageNum, Integer pageSize){
		// 设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		List<WxworkStoreVo> storeList = wxworkStoreMapper.listStoreByQuery(query);
		PageInfo<WxworkStoreVo> pageInfo = new PageInfo<WxworkStoreVo>(storeList);
		return new PageData(pageInfo.getTotal(), pageInfo.getList());
	}
	
	/**
	 * 批量查询门店信息(不分页)
	 * @param cardDo
	 * @return
	 */
	public List<WxworkStoreVo> listStoreByQuery(Query query){
		return wxworkStoreMapper.listStoreByQuery(query);
	}
	
	/**
	 * 查询一个门店详情
	 * @param storeId
	 * @return
	 */
	public WxworkStoreVo getStoreById(String storeId) {
		return wxworkStoreMapper.getStoreById(storeId);
	}
	
	/**
	 * 新增一个门店
	 * @param storeDo
	 */
	public int insert(WxworkStoreDo storeDo) {
		return wxworkStoreMapper.insert(storeDo);
	}
	
	/**
	 * 更新门店信息
	 * @param storeDo
	 * @return
	 */
	public int update(WxworkStoreDo storeDo) {
		return wxworkStoreMapper.update(storeDo);

	}
	
	/**
	 * 删除一个门店
	 * @param storeDo
	 * @return
	 */
	public int delete(String storeId) {
		return wxworkStoreMapper.delete(storeId);

	}
	
	/**
	 * 检查当前门店编号是否存在
	 * @param storeCode
	 * @return
	 */
	public boolean isExist(String storeCode) {
		Query query = new Query();
		query.put("storeCode", storeCode);
		List<WxworkStoreVo> storeList = wxworkStoreMapper.listStoreByQuery(query);
		if(storeList.size() >= 1) {
			return true;
		}
		return false;
	}
}
